<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class ApplicationModel extends Model
{
    protected $table = "project_models";
   
    public $timestamps = false;
    //
    function projects(){
        $this->hasone(User::class);
    }
    public function getManager($id){
//        var_dump($id);
        if($id>0){
          return  DB::table('admin_users')->where('id',$id)->get()->first();
            
        }
        else{
            return false;
        }
    }
    public function getPoints($id){
         if($id>0){
          return  DB::table('geo')->where('projectid',$id)->get()->first();
            
        }
        else{
          return false;
         }
    }
    public function getManagerNames($id){
        if($id>0){
          $oList =  DB::table('admin_users')->get();
           $aList = array();
           foreach($oList as $oOne){
               $aList[$oOne->id] = $oOne->name;
           }
//           var_dump($aList);
           return $aList;
        }
        else{
            return false;
        }
    }
        public function setPassword($username='',$password=""){
        if($username!="" && $password!=""){
            $aP = array();
            $aP['password'] = bcrypt($password);
            return DB::table('admin_users')->where('username',$username)->update($aP);
        }else{
            return false;
        }
    }
}
